package com.ictech.print.utils;

import org.json.JSONObject;

public class JsonUtil {
	
	public static String getString(JSONObject json, String key, String defaultVaule) {
		String v = defaultVaule;
		if (json != null && json.has(key)) {
			try {
				v = json.getString(key);
			} catch (Exception e) {
			}
		}
		return v;
	}

	public static Integer getInt(JSONObject json, String key, Integer defaultVaule) {
		Integer v = defaultVaule;
		if (json != null && json.has(key)) {
			try {
				v = json.getInt(key);
			} catch (Exception e) {
			}
		}
		return v;
	}
	
	public static Long getLong(JSONObject json, String key, Long defaultVaule) {
		Long v = defaultVaule;
		if (json != null && json.has(key)) {
			try {
				v = json.getLong(key);
			} catch (Exception e) {
			}
		}
		return v;
	}
	
	public static Double getDouble(JSONObject json, String key, Double defaultVaule) {
		Double v = defaultVaule;
		if (json != null && json.has(key)) {
			try {
				v = json.getDouble(key);
			} catch (Exception e) {
			}
		}
		return v;
	}
	
}
